(function($) {
  $.fn.getProductDetail = function(options) {
    options = $.extend({
      lookupResource: '../../sys/com/control/ProductServices.php?action=queryAllBySubType',
      asc : 'asc',
      orderByField : 'sell_price',
      type :'1'
    
    },options||{});    
      $.ajax({
        url: options.lookupResource,
        type: 'get',
        data: options,
        dataType: 'html',
        success: function(data) {
        	data=jQuery.parseJSON(data);
        	if(data.length>0){

        		var txtLength=30;

	        	var inner='<input hidden name="type" value="'+data[0].sort+'"><div><table id="table1" width="740" cellspacing="0" cellpadding="0"><tr>';

	        	$.each(data,
	        		function(index,value){
	 				if(index!=0 && index%4==0){
						inner+="</tr><tr>";
					}
	        		inner+='<td width="170"><table width="168" cellspacing="0" cellpadding="0">	<tr><td><table width="168" cellspacing="0" cellpadding="0">	<tr><td height="10" colspan="3">&nbsp;</td></tr><tr><td colspan="3"><img src="../images/products_picture_fram_1.jpg" width="170" height="3" /></td>	</tr><tr><td width="3"><img src="../images/products_picture_fram_2.jpg"	width="3" height="170" /></td><td width="164">	<div align="center">';
	        		inner+='<img width="150px" height="150px" src="../../admin/product/images/'+value.pic+'" class="link" value="'+value.p_id+'" width="150" height="150" alt="" style="background-color: #FF0000" />';
	        		inner+='</div></td>	<td width="3"><img src="../images/products_picture_fram_2.jpg"	width="3" height="170" /></td>	</tr><tr><td height="3" colspan="3"><img src="../images/products_picture_fram_1.jpg" width="170" height="3" /></td>	</tr>	<tr><td height="10" colspan="3"><div align="center"></div>	</td></tr><tr><td colspan="3" class="style59">';
	        		inner+='<div align="center">［'+value.p_name+'］</div>';
//	        		inner+='<div align="center">［'+value.attr+'］</div>';
//	        		var content="";
//	        		try
//	        		  {
//	        			if(value.prod_txt.length>txtLength){
//		        			content=value.prod_txt.substring(0,txtLength-1)+"...";
//		        		}else{
//		        			content=value.prod_txt;
//		        		}
//	        		  }
//	        		catch(err)
//	        		  {
//	        		  //Handle errors here
//	        		  }
//	        		inner+='<div align="center">'+content+'</div>';
	        		inner+='</td></tr><tr><td colspan="3" class="style59">';
	        		inner+='</td></tr><tr>	<td colspan="3" class="style59"><div align="center"></div>	<div align="center"></div>	<div align="center"></div>	</td></tr><tr><td colspan="3">';
	        		inner+='<div align="center" class="style59">NT$'+
			        		value.price+'</div>';
	        		inner+='</td></tr><tr><td height="7" colspan="3" class="style59">';
	        		inner+='<div align="center">NT$'+value.sell_price+'</div>';
	        		inner+='</td></tr></table></td></tr></tbody></table></td>';
	        	});
	        	inner+="</tr></table></div>";
	        	
        	}else{
        		inner="目前無商品資料";
        	}
        	$('#productDetail').html("").html(inner);
        	$("img[class=link]").each(
    				function(index,value){
    					$(this).css("cursor","pointer").click(
    							function(){
    								window.location='../contant/content.php?pa_id='+$(this).attr('value');
    							});
    				}
    			);
        	$("#table1").tablePagination({"rowsPerPage" : '90'});
          },
          error : function(data){
        	  alert(data);
          }
        });
  }
})(jQuery);
//function openProductDetail()
//{
//	window.location='/shopcarda1/List_pages/contant/content.php';
//}
$(document).ready(
	function(){
//		var option={
//				'asc':'asc',
//				orderByField : 'sell_price'
//		};

		$('#productDetail').getProductDetail();
	}
);
